package cn.com.scooper.controller.data.ks;

import cn.com.scooper.common.resp.APIRespJson;
import cn.com.scooper.common.resp.ResultCode;
import cn.com.scooper.pojo.dto.ks.ReportActualDataDto;
import cn.com.scooper.pojo.dto.ks.ReportAlarmDataDto;
import cn.com.scooper.service.ks.KSReportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 矿山物联上报实时及报警数据
 */
@RestController
@RequestMapping("/ext/ksReport")
@Validated
public class KSReportDataController {

    @Autowired
    private KSReportDataService ksReportDataService;

    /**
     * 矿山实时数据接收
     *
     * @param reportActualDataDto
     * @return
     */
    @PostMapping("/actualData/{enterpriseName}")
    @ResponseBody
    public APIRespJson actualData(@PathVariable("enterpriseName") String enterpriseName, @Valid @RequestBody ReportActualDataDto reportActualDataDto, BindingResult bindingResult){
        if( bindingResult.hasErrors() ){
            return new APIRespJson(ResultCode.PARAM_ERR,"存在必填参数未填写！");
        }
        int result = ksReportDataService.recvActualData(reportActualDataDto, enterpriseName);
//        if( result < 0 ){
//            return new APIRespJson(ResultCode.FAIL,"矿山实时数据接收失败！");
//        }
        return new APIRespJson();
    }

    /**
     * 矿山告警数据接收
     *
     * @param reportAlarmDataDto
     * @return
     */
    @PostMapping("/alarmData/{enterpriseName}")
    @ResponseBody
    public APIRespJson alarmData(@PathVariable("enterpriseName") String enterpriseName, @Valid @RequestBody ReportAlarmDataDto reportAlarmDataDto, BindingResult bindingResult){
        if( bindingResult.hasErrors() ){
            return new APIRespJson(ResultCode.PARAM_ERR,"存在必填参数未填写！");
        }
        int result = ksReportDataService.recvAlarmData(reportAlarmDataDto, enterpriseName);
//        if( result < 0 ){
//            return new APIRespJson(ResultCode.FAIL,"矿山告警数据接收失败！");
//        }
        return new APIRespJson();
    }
}
